<template>
  <div class="home">
    {{ food }}
    <img alt="Vue logo" src="../assets/img/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <button @click="handleClick">返回上一页</button>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  props: {
    food: {
      type: String
    }
  },
  beforeRouteEnter (to, from, next) {
    //  before
    console.log(to.name)
    next(vm => {
      console.log(vm)
    })
  },
  beforeRouteLeave (to, from, next) {
    const leave = confirm('您确认要离开吗')
    if (leave) {
      next()
    } else {
      next(false)
    }
  },
  beforeRouteUpdate (to, from, next) {
    console.log(to.name, from.name)
  },
  name: 'home',
  components: {
    HelloWorld
  },
  methods: {
    handleClick () {
      // this.$router.go(-1)
      // this.$router.back()
      this.$router.push('/parent')
    }
  }
}
</script>
